package chezsmithybot;

import com.google.appengine.api.datastore.Key;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import java.util.Stack;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
class WaveStack {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	Key key;
	
	@Persistent
	private String waveID;
	
	@Persistent
	private Stack<String> waveStack;
	
	public WaveStack() {
		waveStack = new Stack<String>();
	}
	
	public Key getKey() {
		return key;
	}
	
	public String getwaveID() {
		return waveID;
	}
	
	public void setwaveID(String waveID) {
		this.waveID = waveID;
	}
	
	public void pushstackVal(String stackVal) {
		if (waveStack == null) {
			waveStack = new Stack<String>();
		}
		waveStack.push(stackVal);
	}
	
	public String popstackVal() {
		if (!(waveStack == null) || !waveStack.empty()) {
			return waveStack.pop();
		} else {
			return "";
		}
	}
	
	public Integer sumstack() {
		Integer stackSum = 0;
		for (String s : waveStack) {
			stackSum += Integer.valueOf(s);
		}
		return stackSum;
	}
	
	public String printstack() {
		if (!(waveStack == null) || !waveStack.empty()) {
			String retVal = "Stack Contents: ";
			for (String stackVal : waveStack) {
				retVal = retVal.concat(stackVal + " ");
			}
			return retVal;
		} else {
			return "Stack is Empty";
		}
	}
	
}
